package de.unidue.langtech.teaching.pp.example;

import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.util.JCasUtil;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;

import de.unidue.langtech.teaching.pp.type.RelationType;
import de.unidue.langtech.teaching.pp.type.TrueValueType;

/* Evaluator shows how many relations are correct
 * @author betuel
*/
public class Evaluator
    extends JCasAnnotator_ImplBase
{

    private int correct;
    private int nrOfSentence;
    
    
     // This is called BEFORE any documents are processed.
     
    @Override
    public void initialize(UimaContext context)
        throws ResourceInitializationException
    {
        super.initialize(context);
        correct = 0;
        nrOfSentence = 0;
    }
    
    
   
     // This is called ONCE for each document
     
    @Override
    public void process(JCas jcas)
        throws AnalysisEngineProcessException
    {
        nrOfSentence++; 
        
        RelationType relation = JCasUtil.selectSingle(jcas, RelationType.class);
        TrueValueType trueValue = JCasUtil.selectSingle(jcas, TrueValueType.class);

        System.out.println(trueValue.getTrueValue() + " detected as " + relation.getRelation());
        if (relation.getRelation().equals(trueValue.getTrueValue())) {
            correct++;
        }
    }


     
     //This comes when all Sentence have been processed
     
    @Override
    public void collectionProcessComplete()
        throws AnalysisEngineProcessException
    {
        super.collectionProcessComplete();
        
        System.out.println(correct + " out of " + nrOfSentence + " are correct.");
    
        // Anzahl der korrekten Saetze bzw. Beziehungen soll am Ende angezeigt werden
    }
}